package com.example.supermarket.controller;

import com.example.supermarket.pojo.*;
import com.example.supermarket.service.BusinessService;
import org.mockito.internal.matchers.Or;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/business")
public class BusinessController {
    @Autowired
    private BusinessService businessService;

    @PostMapping("/createShop")
    public Result createShop(@RequestBody Shop shop){
        businessService.createShop(shop);
        return Result.success();
    }

    @PostMapping("/createShopItem")
    public Result createShopItem(@RequestBody Item item){
        businessService.createShopItem(item);
        return Result.success();
    }

    @PostMapping("/listItem")
    public Result listItem(Integer shopId,Integer itemId){
        businessService.listItem(shopId,itemId);
        return Result.success();
    }

    @DeleteMapping("/delistItem")
    public Result delistItem(Integer shopId,Integer itemId){
        businessService.delistItem(shopId,itemId);
        return Result.success();
    }

    @GetMapping("/getBusinessInfo")
    public Result<Business> getBusinessInfo(){
        Business business=businessService.getBusinessInfo();
        return Result.success(business);
    }

    @GetMapping("/getOrderByShopId")
    public Result<List<Order>> getOrderByShopId(Integer shopId){
        List<Order> list=businessService.getOrderByShopId(shopId);
        return Result.success(list);
    }

    @PostMapping("/confirmOrder")
    public Result confirmOrder(Integer orderId){
        businessService.confirmOrder(orderId);
        return Result.success();
    }

    @PostMapping("/cancelOrder")
    public Result cancelOrder(Integer orderId){
        businessService.cancelOrder(orderId);
        return Result.success();
    }


}
